<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="button1">点击按钮 1</button>
    <button id="button2">点击按钮 2</button>
    <button id="button3">点击按钮 3</button>

    <script>
        let button1 = document.getElementById('button1'),
            button2 = document.getElementById('button2'),
            button3 = document.getElementById('button3');

        const setCommand = function (button, fn) {
            button.onclick = fn;
        }

        let MenuBar = {
            add() {
                console.log('add');
            }
        }

        setCommand(button1, MenuBar.add)
    </script>
</body>

</html>